package com.ruoyi.common.utils;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.resource.OperatorUserSystem;

/**
 * @Description:
 * @Company: 北京卡拉卡尔股份技术有限公司
 * @Author: Darren Ho
 * @Date: 9/29/2020 14:41
 */
public final class RedisCacheKeyHelper {

    public final static String SPLIT = ":";

    private RedisCacheKeyHelper() {
    }

    /**
     * 产品 在线使用人数
     */
    public static String getProductOnlineUserKey(Long productId) {
        return Constants.PRODUCT_USAGE_KEY + productId;
    }

    /**
     * 产品用户在线使用人数
     */
    public static String getProductUserOnlineUsagePrefixKey(Long productId, Long productUserId) {
        return getProductOnlineUserKey(productId) + SPLIT + productUserId;
    }

    /**
     * 产品-产品用户-客户端用户
     */
    public static String getProductUserOnlineUsageKey(Long productId, Long productUserId, Long clientUserId) {
        return getProductUserOnlineUsagePrefixKey(productId, productUserId) + SPLIT + clientUserId;
    }

    /**
     * 系统用户唯一key
     */
    public static String getUserUniqueKey(OperatorUserSystem operatorUserSystem, String deviceId) {
        return getUserUniqueKeyPrefix(operatorUserSystem) + SPLIT + deviceId;
    }

    /**
     * 系统用户key前缀
     */
    public static String getUserUniqueKeyPrefix(OperatorUserSystem operatorUserSystem) {
        return Constants.LOGIN_TOKEN_KEY + operatorUserSystem.name();
    }

    public static String getProductUser2ProductConcurrentLockKey(Long productUserId, Long productId) {
        return Constants.PRODUCT_USER_2_PRODUCT_CONCURRENT_LOCK + productUserId + SPLIT + productId;
    }

    public static String getProductUserLoginTimeKeyPrefix(Long productUserId) {
        return Constants.PRODUCT_USER_LOGIN_TIME_KEY + productUserId;
    }

    public static String getProductUserLoginTimeKey(Long productUserId, Long userId) {
        return getProductUserLoginTimeKeyPrefix(productUserId) + SPLIT + userId;
    }

    /**
     * 内置账号cookie key
     */
    public static String getProductUserCookieKey(Long productUserId) {
        return Constants.PRODUCT_USER_COOKIE_KEY + productUserId;
    }



    public static String getUserTokenUniqueKey(OperatorUserSystem operatorUserSystem, Long userId) {
        return Constants.USER_TOKEN_KEY + operatorUserSystem.name() + SPLIT + userId;
    }

    /**
     * 亚马逊网站 cookie 刷新开关key
     */
    public static String getMerchantWordCookieRefreshOnOffKey(Long productUserId) {
        return Constants.COOKIE_REFRESH_ON_OFF + productUserId;
    }


    public static String getClientProductUseTimeKey(String token) {
        return Constants.PROXY_TOKEN + ":" + token;
    }

    public static String getProxyCookiesKey(String key){
        return Constants.COOKIES + ":" + key;
    }
}


